package br.com.mmm.javacenter.framework.view.taglib.html;

import java.util.LinkedList;
import java.util.List;

import org.displaytag.util.HtmlAttributeMap;

import br.com.mmm.javacenter.framework.util.Atributo;

public class HTMLElement {
	private String tagName;
	private Object value;
	private List<HTMLElement> body  = new LinkedList<HTMLElement>();
	private List<Atributo> atributos = new LinkedList<Atributo>();
	
	public HTMLElement(String tagName, List<Atributo> atributos) {
		super();
		this.tagName = tagName;
		this.atributos = atributos;
	}
	public HTMLElement(String tagName) {
		super();
		this.tagName = tagName;
	}
	
	public String getTagName() {
		return tagName;
	}
	public void setTagName(String tagName) {
		this.tagName = tagName;
	}
	public List<Atributo> getAtributos() {
		return atributos;
	}
	public void addAtributo(String name,String value ) {
		this.atributos.add(new Atributo(name, value));
	}
	public void addAtributo(Atributo ... atributo) {
		for(Atributo a:atributo)
			this.atributos.add(a);
	}
	public void setAtributos(List<Atributo> atributos) {
		this.atributos = atributos;
	}
	
	public Object getValue() {
		return value;
	}
	public void setValue(Object value) {
		this.value = value;
	}
	public List<HTMLElement> getBody() {
		return body;
	}
	public void addChild(HTMLElement body) {
		this.body.add(body);
	}
	public void setBody(List<HTMLElement> body) {
		this.body = body;
	}
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("<" + tagName);
		for(Atributo atributo:atributos){
			sb.append(' ').append(atributo).append(' ');
		}
		sb.append('>').append(value==null?"":value);
		for(HTMLElement atributo:body){
			sb.append(atributo);
		}
		sb.append("<" + tagName + "/>");
		return sb.toString();
	}
}
